package com.example.demo;

import groovy.lang.GroovyShell;
import groovy.lang.Script;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class ConsoleApp implements CommandLineRunner {

  final static Log log = LogFactory.getLog(ConsoleApp.class);

  public static void byGroovyShell() {
    GroovyShell shell = new GroovyShell();
    long t1 = System.currentTimeMillis();
    Script script = shell.parse("12+23");
    for (int i = 0; i < 100; i++) {
      Object result = script.run();
      assert result.equals(35);
    }
    long t2 = System.currentTimeMillis();
    log.info(t2 - t1);
  }

  @Override
  public void run(String... args) throws Exception {
    log.info("ConsoleApp.run");
    byGroovyShell();

    System.exit(0);
  }
}
